<!-- <template>
    <van-nav-bar title="二级" left-text="返回" left-arrow @click-left="onClickLeft" />

    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
           <router-link v-for="i in list" :to="'/xiangqing/' + i.goods_id">
                <van-card :price="i.goods_price" :title="i.goods_name"
                    :thumb="i.goods_big_logo?i.goods_big_logo:'https://tse2-mm.cn.bing.net/th/id/OIP-C.N_msAr5FxErn-Upzco0bqgAAAA?rs=1&pid=ImgDetMain'" />
            </router-link>
        </van-list>
    </van-pull-refresh>

</template>

<script setup>
import { showToast } from 'vant';
import { useRoute ,useRouter} from 'vue-router';
const router=useRouter()
import { reactive, ref } from 'vue';
import { lb } from '@/api/api';
const route=useRoute()
const list = ref([]);
const loading = ref(false);
const finished = ref(false);
const refreshing = ref(false);
const num = reactive({
    pagenum: 1,
    pagesize: 7,
})
const total = ref(0)



const onLoad = () => {

    if (refreshing.value) {
        list.value = []
        refreshing.value = false
        num.pagenum = 1
        total.value = 0
    }
    const max = Math.ceil(total.value / num.pagesize)
    if (max == 0) {
        showToast('初始化')
    } else {
        if (num.pagenum < max) {
            num.pagenum++
        } else {
            finished.value = true
            showToast('没有更多了')
            return
        }
    }

    lb({
        cid:route.params.goods_id,
        ...num
    }).then(res => {
        console.log('二级', res)
        list.value = list.value.concat(res.data.message.goods)
        list.total = res.data.message.total
        loading.value = false
    })
}

const onRefresh = () => {
    // 清空列表数据
    finished.value = false;

    // 重新加载数据
    // 将 loading 设置为 true，表示处于加载状态
    loading.value = true;
    onLoad();
};
</script>

<style lang="scss" scoped></style> -->

<template>
     <van-nav-bar title="二级" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <router-link v-for="i in list" :to="'/xiangqing/' + i.goods_id">
                <van-card :price="i.goods_price" :title="i.goods_name"
                    :thumb="i.goods_big_logo?i.goods_big_logo:'https://tse2-mm.cn.bing.net/th/id/OIP-C.N_msAr5FxErn-Upzco0bqgAAAA?rs=1&pid=ImgDetMain'" />
            </router-link>

        </van-list>
    </van-pull-refresh>

</template>

<script setup>
import { ref,reactive} from 'vue';
import { lb } from '@/api/api';
import { showToast } from 'vant';
const onClickLeft = () => router.go(-1);
import { useRoute,useRouter } from 'vue-router';
const route=useRoute()
const router=useRouter()
const list = ref([]);
const loading = ref(false);
const finished = ref(false);
const refreshing = ref(false);
const num = reactive({
    pagenum: 1,
    pagesize: 7,
})
const total = ref(0)

const onLoad = () => {
    if (refreshing.value) {
        list.value = []
        refreshing.value = false
        num.pagenum = 1,
            total.value = 0
    }
    const max = Math.ceil(total.value / num.pagesize)
    if (max == 0) {
        showToast('初始化')
    }else {
        if (num.pagenum < max) {
            num.pagenum++
        } else {
            finished.value = true
            showToast('没有更多了')
            return
        }
    }

    lb({
        cid:route.params.goods_id,
        ...num
    }).then(res=>{
        console.log('商品列表',res)
        list.value=list.value.concat(res.data.message.goods)
         total.value = res.data.message.total
        loading.value = false
    })
}


const onRefresh = () => {
    // 清空列表数据
    finished.value = false;

    // 重新加载数据
    // 将 loading 设置为 true，表示处于加载状态
    loading.value = true;
    onLoad();
};
</script>

<style lang="scss" scoped></style>